﻿using UnityEngine;

namespace MyFramework.Singleton
{
    /// <summary>
    /// 挂载式MonoBehavior单例模式
    /// </summary>
    /// <typeparam name="T">需要的类型</typeparam>
    [DisallowMultipleComponent]
    public class SingletonMono<T> : MonoBehaviour where T : MonoBehaviour
    {
        private static T _instance;

        protected virtual void Awake()
        {
            if (!_instance)
            {
                _instance = this as T;
                DontDestroyOnLoad(gameObject);
            }
            else
            {
                Destroy(this);
            }
        }
    }
}